<template>
  <div class="login-wrap">
    <!-- inset 是否展示为圆角卡片风格 -->
    <div class="title">欢迎来到网易云音乐</div>
    <van-cell-group inset>
      <van-field v-model="tel" type="tel" label="手机号" clearable placeholder="请输入手机号" />
      <van-field v-model="sms" center clearable label="短信验证码" placeholder="请输入短信验证码">
        <template #button>
          <van-button size="small" type="warning">发送验证码</van-button>
        </template>
      </van-field>
      <van-field
        v-model="password"
        :type="showPassword ? 'text' : 'password'"
        label="密码"
        placeholder="请输入密码"
        :right-icon="showPassword ? 'eye-o' : 'closed-eye'"
        @click-right-icon="showPassword = !showPassword"
        clearable
      >
      </van-field>
    </van-cell-group>
    <div class="submit-btn">
      <van-button type="warning" @click="handleLogin">登录</van-button>
    </div>
    <div class="logo">
      <img :src="getImageUrl('wangyiyun')" alt="wangyiyun" />
      <div class="tip-txt">音乐的力量</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getImageUrl } from '@/utils/index'
import { userLogin, loginParams } from '@/api/login'

const tel = ref('')
const sms = ref('')
const password = ref('')
const showPassword = ref(false)

const handleLogin = async () => {
  try {
    const params: loginParams = {
      phone: tel.value,
      password: password.value
    }
    let res = await userLogin(params)
    console.log(res, 'res')
  } catch (error) {
    console.log(error, 'handleLogin')
  }
}
</script>

<style lang="less" scoped>
.login-wrap {
  background-color: @bg-color;
  height: 100vh;
  .title {
    text-align: center;
    padding: 40px;
    font-size: @font-32;
    color: @font-color;
  }
}
.van-cell-group,
.van-cell {
  background: @bg-color;
}

// 深度选择器 单个生效
:deep(input.van-field__control) {
  color: @font-color;
}

:deep(.van-field__label) {
  color: @font-color;
}
:deep(.van-field__right-icon) {
  color: @font-color;
}

.logo {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: @font-color;
  img {
    width: 160px;
    height: 160px;
  }
  .tip-txt {
    font-size: @font-32;
    margin-top: 30px;
  }
}

// placeholder颜色改变
// :deep(input.van-field__control::-webkit-input-placeholder) {
//   color: @font-color;
// }
</style>
